function ajax(options) {

    if (!options.url) return

    if (window.ActiveXObject) {
        var xhr = new ActiveXObject('Microsoft.XMLHTTP')
    } else {
        var xhr = new XMLHttpRequest()
    }


    var arr = []
    for (var attr in options.data) {
        arr.push(attr + '=' + options.data[attr])
    }

    var str = arr.join('&')


    options.type = options.type || 'GET'

    if (options.type.toUpperCase() === 'GET') {
        xhr.open('GET', options.url + '?' + str, true)
        xhr.send()
    } else {
        xhr.open('POST', options.url, true)
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded')
        xhr.send(str)
    }

    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            options.success && options.success(xhr.responseText)
        } else {
            options.error && options.error(xhr.responseText)
        }
    }
}
